package com.keon.jianbao.util;

import android.content.Context;

import com.keon.jianbao.AppContext;
import com.keon.jianbao.base.BaseActivity;
import com.tencent.mm.sdk.modelmsg.SendMessageToWX;
import com.tencent.mm.sdk.modelmsg.WXMediaMessage;
import com.tencent.mm.sdk.modelmsg.WXWebpageObject;
import com.tencent.mm.sdk.openapi.IWXAPI;

/**
 * Created by keon on 2015/10/28.
 */
public class WechatUtils {
    public static int TYPE_FRIEND = 1;
    public static int TYPE_TIMELINE = 2;


    BaseActivity mContext;
    IWXAPI mApi;

    public WechatUtils(Context context) {

        mContext = (BaseActivity) context;

        mApi = AppContext.WXapi;

        if (!mApi.isWXAppInstalled()) {
            mContext.showToast("请先安装微信应用");
            return;
        }
        if (!mApi.isWXAppSupportAPI()) {
            mContext.showToast("请先更新微信应用");
            return;
        }

        // 将该app注册到微信
        mApi.registerApp(ConstantUtils.WX_APP_ID);

      /*  final SendAuth.Req req = new SendAuth.Req();
        req.scope = "snsapi_userinfo";
        req.state = "wx_login";
        mApi.sendReq(req);*/
    }

    public void wechatShare(String url, int flag) {
        WXWebpageObject webpage = new WXWebpageObject();
        webpage.webpageUrl = url;
        WXMediaMessage msg = new WXMediaMessage(webpage);
        msg.title = "这里填写标题";
        msg.description = "这里填写内容";
        //这里替换一张自己工程里的图片资源
/*        Bitmap thumb = BitmapFactory.decodeResource(getResources(), R.drawable.share_logo);
        msg.setThumbImage(thumb);*/

        SendMessageToWX.Req req = new SendMessageToWX.Req();
        req.transaction = String.valueOf(System.currentTimeMillis());
        req.message = msg;
        req.scene = flag == 0 ? SendMessageToWX.Req.WXSceneSession : SendMessageToWX.Req.WXSceneTimeline;
        mApi.sendReq(req);
    }
}
